﻿using UnityEngine;
using UnityEngine.Serialization;


#if UNITY_EDITOR
using UnityEditor;
#endif

namespace GameToolkit.BehaviourTree
{

    /// <summary>
    /// (行为树资源)组件资源
    /// </summary>
    [System.Serializable]
    public abstract class Composite : IAliveDescripter
    {
        [SerializeField, HideInInspector, JsonCloneable(false), FormerlySerializedAs("guid")]
        internal string _guid;
        public string guid => _guid;
#if UNITY_EDITOR

        [SerializeField, HideInInspector]
        internal Vector2 m_Position;

        internal virtual void ResetGUID()
        {
            _guid = GUID.Generate().ToString();
        }

#endif
        public abstract BehaviourTreeObject Create();
        public virtual string GetDescription() { return null; }
    }

    /// <summary>
    /// 继承该类以扩展(控制节点+行为节点)
    /// </summary>
    public abstract partial class ExecutableComposite : Composite
    {
        [SerializeField]
        internal ConditionLogic m_ConditionLogic;

        [SerializeReference, HideInInspector]
        internal Composite[] m_Decorations;

        [SerializeReference, HideInInspector, JsonCloneable(false)]
        internal Composite[] m_Children;

#if UNITY_EDITOR
        internal sealed override void ResetGUID()
        {
            base.ResetGUID();
            var len = m_Decorations == null ? 0 : m_Decorations.Length;
            for (int i = 0; i < len; i++)
            {
                m_Decorations[i]?.ResetGUID();
            }
        }

#endif 

    }

}
